#include "View.h"

/********************************************
/*              Members
/********************************************/

    /****************************************
    /*          Constructors
    /****************************************/

        View::View(){
            Initialize(PERSPECTIVE);
        }

        View::View(ProjectionMode mode){
            Initialize(mode);
        }

        void View::Initialize(ProjectionMode mode){

            m_Mode      =mode;
            m_ProjectionMatrix    =   new Matrix4();

            if(mode==ORTHO){
                m_ProjectionMatrix=           &Matrix4::Ortho(-5,5,-5,5,0.1,1000);
            }else if(mode==PERSPECTIVE){
                m_ProjectionMatrix    =       &Matrix4::Perspective(1.5,1.0f,1.0f,1000);
            }
            m_ViewMatrix      =   new Matrix4();
            SetTransform(new Transform(*m_ViewMatrix));
            m_Transform->IsView=true;
            m_Transform->Translation(vec4(-10.0f, -10.0f, 5.0f));
        }

    /****************************************
    /*          Methods
    /****************************************/

    /****************************************
    /*         Get
    /****************************************/

        Transform & View::GetTransform(){
            return *m_Transform;
        }

        Matrix4 &   View::ProjectionMatrix(){
            return *m_ProjectionMatrix;
        }

        Matrix4 &   View::ViewMatrix(){
            return *m_ViewMatrix;
        }



    /****************************************
    /*         Set
    /****************************************/

        void View::SetTransform(Transform &transform){
            m_Transform =   &transform;
        }

        void View::SetTransform(Transform *transform){
            m_Transform =   transform;
        }

        void View::ViewMatrix(Matrix4 &matrix){
            m_ViewMatrix=   &matrix;
        }

        void View::ViewMatrix(Matrix4 *matrix){
            m_ViewMatrix    =matrix;
        }

        void View::ProjectionMatrix(Matrix4 &matrix){
            m_ProjectionMatrix  =   &matrix;
        }

        void View::ProjectionMatrix(Matrix4 *matrix){
            m_ProjectionMatrix  =   matrix;
        }



   /*     void View::SendMatrix(GLuint programID)
        {
            glUniformMatrix4fv(glGetUniformLocation(programID, "u_ProjectionMatrix"),   1, GL_TRUE, m_Projection.array);
            glUniformMatrix4fv(glGetUniformLocation(programID, "u_ViewMatrix"),         1, GL_TRUE, m_ViewMatrix->array);
        }
    */
    /****************************************/
    /*          Virtual Methods             */
    /****************************************/

       void View::Display()
        {

        }/*

        void View::Update()
        {
            float val = 0.1;

            /*if( sf::Keyboard::isKeyPressed(sf::Keyboard::A))
            {
                *m_Position += m_Forward * val;
            }
            if( sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
            {
               *m_Position -= m_Forward * val;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
            {
              m_Position->x +=val;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
            {
               m_Position->x +=val;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
            {
                m_Position->x +=val;
            }
            if( sf::Keyboard::isKeyPressed(sf::Keyboard::X))
            {
                m_Position->x +=val;
            }

            if(Application::s_CurrentEvent.type == sf::Event::MouseButtonPressed)
            {
                    xAnchor=Application::s_CurrentEvent.mouseButton.x;
                    yAnchor=Application::s_CurrentEvent.mouseButton.y;
                    buttonPressed=true;
            }
            if(Application::s_CurrentEvent.type == sf::Event::MouseButtonReleased)
            {
                    buttonPressed=false;
                    xAnchor=-1;
                    yAnchor=-1;
            }
            if(Application::s_CurrentEvent.type == sf::Event::MouseMoved)
            {
                if(buttonPressed)
                {
                    int difX = xAnchor-Application::s_CurrentEvent.mouseMove.x;
                    int difY = yAnchor-Application::s_CurrentEvent.mouseMove.y;

                    RotateView(difX, difY);

                    xAnchor=Application::s_CurrentEvent.mouseMove.x;
                    yAnchor=Application::s_CurrentEvent.mouseMove.y;
                }
            }
*/
        /*    m_ViewMatrix->Identity();
            *m_ViewMatrix  =    (Quaternion::Euler(-teta, -phi,0.0 )).RotationMatrix();
            m_ViewMatrix->Translate(m_Position->x, m_Position->y, m_Position->z);



        }



        void View::RotateView(int x, int y)
        {
            phi     +=  (float)x*0.005;
            teta    +=  (float)y*0.005;
        }

        void View::UpdateMatrix()
        {
            m_ViewMatrix->Identity();
        }
*/
    /****************************************/
    /*          Operator Overload           */
    /****************************************/


    /****************************************/
    /*          Static                      */
    /****************************************/

        /****************************************/
        /*              Properties              */
        /****************************************/

       //     View *  View::MainView;

        /****************************************/
        /*          Methods                     */
        /****************************************/


